package com.vivebest.utils.kd.service;

import com.vivebest.utils.chc.domain.ConsulHealthCheck;
import com.vivebest.utils.chc.service.ConsulHealthCheckService;
import com.vivebest.utils.common.constant.enums.CmdEnums;
import com.vivebest.utils.common.domain.TransportTemplate;
import com.vivebest.utils.common.dto.CmdResponseDto;
import com.vivebest.utils.common.exception.BizException;
import com.vivebest.utils.common.service.CmdTemplateTransformService;
import com.vivebest.utils.common.utils.StringUtils;
import com.vivebest.utils.kd.config.PodVersionConfig;
import com.vivebest.utils.kd.constant.MsgConstants;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.io.*;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.*;

/**
 * <p>
 * k8s部署
 * </p>
 *
 * @author zsk
 * @date 2020/8/10 下午2:56
 */
@Service
@Log4j2
public class K8sDeployService {

    @Value("${k8s.base-work-path}")
    private String baseWorkPath;
    private final String consulServiceFileName="/opt/app/file/banking-consul-service.yaml";
    @Value("${k8s.consul.health-check.retry-num}")
    private int retryNum;
    @Value("${k8s.consul.health-check.retry-sec}")
    private int retrySec;
    private final float versionStep=0.1f;
    @Value("${k8s.docker.domain}")
    private String dockrerRegDomain;
    private final String configDirName="config";
    private final String tarSuffix="-app-1.0-SNAPSHOT.tar.gz";
    private final String configmapSuffix="-configmap";
    private final String podPreffix="pod-";
    private final String podTplSuffix="-tpl.yaml";
    private final String podSuffix=".yaml";
    @Value("${k8s.pod-version.init-file}")
    private String podVersionInitFile;

    @Autowired
    private ExecutorService executorService;

    @Autowired
    CmdTemplateTransformService cmdTemplateTransformService;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * k8s默认命名空间
     */
    @Value("${k8s.namespace}")
    private String namespace;

    /**
     * @param workPath 基础路径
     * @param file     文件名称
     */
    public CmdResponseDto uncompressTar(String workPath, String file) throws IOException, InterruptedException {
        Map<String, String> argsMap = new HashMap<>(2);
        argsMap.put("workPath", workPath);
        argsMap.put("file", file);

        return cmdTemplateTransformService.executeCmdTmp(CmdEnums.UNCOMPRESS_TAR.getCmdCode(), argsMap);
    }

    public CmdResponseDto uncompressZip(String workPath, String file) throws IOException, InterruptedException {
        Map<String, String> argsMap = new HashMap<>(2);
        argsMap.put("workPath", workPath);
        argsMap.put("file", file);

        return cmdTemplateTransformService.executeCmdTmp(CmdEnums.UNCOMPRESS_ZIP.getCmdCode(), argsMap);
    }

    public CmdResponseDto rm(String filePath) throws IOException, InterruptedException {
        Map<String, String> argsMap = new HashMap<>(1);
        argsMap.put("filePath", filePath);

        return cmdTemplateTransformService.executeCmdTmp(CmdEnums.RM.getCmdCode(), argsMap);
    }

    public CmdResponseDto createDockerImage(String workPath, String tag) throws IOException, InterruptedException {
        Map<String, String> argsMap = new HashMap<>(2);
        argsMap.put("workPath", workPath);
        argsMap.put("tag", tag);

        return cmdTemplateTransformService.executeCmdTmp(CmdEnums.CREATE_DOCKER_IMAGE.getCmdCode(), argsMap);
    }

    public CmdResponseDto changeSeparator(String file) throws IOException, InterruptedException {
        Map<String, String> argsMap = new HashMap<>(1);
        argsMap.put("file", file);

        return cmdTemplateTransformService.executeCmdTmp(CmdEnums.CHANGE_SEPARATOR.getCmdCode(), argsMap);
    }

    public CmdResponseDto pushDockerImage(String tag) throws IOException, InterruptedException {
        Map<String, String> argsMap = new HashMap<>(1);
        argsMap.put("tag", tag);

        return cmdTemplateTransformService.executeCmdTmp(CmdEnums.PUSH_DOCKER_IMAGE.getCmdCode(), argsMap);
    }

    public CmdResponseDto createConfigMap(String configFilePath, String configMapName, String namespace) throws IOException, InterruptedException {
        String optionalNamespace = Optional
                .ofNullable(StringUtils.isBlank(namespace) ? null : namespace)
                .orElse(this.namespace);
        Map<String, String> argsMap = new HashMap<>(3);
        argsMap.put("configFilePath", configFilePath);
        argsMap.put("configMapName", configMapName);
        argsMap.put("namespace", optionalNamespace);

        return cmdTemplateTransformService.executeCmdTmp(CmdEnums.CREATE_CONFIG_MAP.getCmdCode(), argsMap);
    }

    public CmdResponseDto createK8sPod(String podFile) throws IOException, InterruptedException {
        Map<String, String> argsMap = new HashMap<>(1);
        argsMap.put("podFile", podFile);

        return cmdTemplateTransformService.executeCmdTmp(CmdEnums.CREATE_K8S_POD.getCmdCode(), argsMap);
    }

    public CmdResponseDto createK8sService(String serviceFile) throws IOException, InterruptedException {
        Map<String, String> argsMap = new HashMap<>(1);
        argsMap.put("serviceFile", serviceFile);

        return cmdTemplateTransformService.executeCmdTmp(CmdEnums.CREATE_K8S_SERVICE.getCmdCode(), argsMap);
    }

    public CmdResponseDto deleteConfigMap(String configMapName, String namespace) throws IOException, InterruptedException {
        String optionalNamespace = Optional
                .ofNullable(StringUtils.isBlank(namespace) ? null : namespace)
                .orElse(this.namespace);
        Map<String, String> argsMap = new HashMap<>(2);
        argsMap.put("configMapName", configMapName);
        argsMap.put("namespace", optionalNamespace);

        return cmdTemplateTransformService.executeCmdTmp(CmdEnums.DELETE_CONFIG_MAP.getCmdCode(), argsMap);
    }

    public CmdResponseDto deleteK8sPod(String podFile) throws IOException, InterruptedException {
        Map<String, String> argsMap = new HashMap<>(1);
        argsMap.put("podFile", podFile);

        return cmdTemplateTransformService.executeCmdTmp(CmdEnums.DELETE_K8S_POD.getCmdCode(), argsMap);
    }

    public CmdResponseDto deleteK8sService(String serviceFile) throws IOException, InterruptedException {
        Map<String, String> argsMap = new HashMap<>(1);
        argsMap.put("serviceFile", serviceFile);

        return cmdTemplateTransformService.executeCmdTmp(CmdEnums.DELETE_K8S_SERVICE.getCmdCode(), argsMap);
    }

    public CmdResponseDto consulCatalogServices(String serviceFile) throws IOException, InterruptedException {
        String optionalServiceFile = Optional
                .ofNullable(StringUtils.isBlank(serviceFile) ? null : consulServiceFileName)
                .orElse(this.consulServiceFileName);
        Map<String, String> argsMap = new HashMap<>(1);
        argsMap.put("serviceFile", optionalServiceFile);

        return cmdTemplateTransformService.executeCmdTmp(CmdEnums.CONSUL_CATALOG_SERVICES.getCmdCode(), argsMap);
    }

    public CmdResponseDto consulWatchChecksService(String serviceFile,String serviceName) throws IOException, InterruptedException {
        String optionalServiceFile = Optional
                .ofNullable(StringUtils.isBlank(serviceFile) ? null : consulServiceFileName)
                .orElse(this.consulServiceFileName);
        Map<String, String> argsMap = new HashMap<>(1);
        argsMap.put("serviceFile", optionalServiceFile);
        argsMap.put("serviceName", serviceName);

        return cmdTemplateTransformService.executeCmdTmp(CmdEnums.CONSUL_WATCH_CHECKS_SERVICE.getCmdCode(), argsMap);
    }

    public void sed(String optFile,String oldStr,String newStr) throws IOException {
        Map<String, String> argsMap = new HashMap<>(1);
        argsMap.put("optFile", optFile);
        argsMap.put("oldStr", oldStr);
        argsMap.put("newStr", newStr);

        cmdTemplateTransformService.executeCmdTmpUnWaitFor(CmdEnums.SED.getCmdCode(), argsMap);
    }

    public List<CmdResponseDto> autoCompletePublishPod(String serviceName) throws IOException, InterruptedException {
        List<CmdResponseDto> cmdResponseDtos=new ArrayList<>(7);
        String podWorkPath=baseWorkPath+ File.separator+serviceName;
        String tarName=podWorkPath+File.separator+serviceName+tarSuffix;
        String dockerImageName=dockrerRegDomain+serviceName;
        String configFilePath=podWorkPath+File.separator+configDirName;
        String configMapName=serviceName+configmapSuffix;
        String podFileNameTpl=podWorkPath+File.separator+podPreffix+serviceName+podTplSuffix;
        String podFileName=podWorkPath+File.separator+podPreffix+serviceName+podSuffix;

        float version= Float.parseFloat((String) Objects.requireNonNull(stringRedisTemplate.opsForHash().get(PodVersionConfig.podVersionHashName, serviceName)));
        version+=versionStep;
        version=Float.parseFloat(String.format("%.1f",version));

        CmdResponseDto cmdResponseDtoForTar=uncompressTar(podWorkPath,tarName);
        changeSeparator(podWorkPath+File.separator+"start.sh");
        assignPodFileVersion(podFileNameTpl,podFileName,version);
        CmdResponseDto cmdResponseDtoForCdi=createDockerImage(podWorkPath,dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForPdi=pushDockerImage(dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForDcm=deleteConfigMap(configMapName,"");
        CmdResponseDto cmdResponseDtoForCcm=createConfigMap(configFilePath,configMapName,"");
        CmdResponseDto cmdResponseDtoForDkp=deleteK8sPod(podFileName);
        CmdResponseDto cmdResponseDtoForCkp=createK8sPod(podFileName);
        cmdResponseDtos.add(cmdResponseDtoForTar);
        cmdResponseDtos.add(cmdResponseDtoForCdi);
        cmdResponseDtos.add(cmdResponseDtoForPdi);
        cmdResponseDtos.add(cmdResponseDtoForDcm);
        cmdResponseDtos.add(cmdResponseDtoForCcm);
        cmdResponseDtos.add(cmdResponseDtoForDkp);
        cmdResponseDtos.add(cmdResponseDtoForCkp);

        consulHealthCheckAfterDeploy(serviceName, cmdResponseDtos, version);
        log.debug("完全pod部署结果:{}",cmdResponseDtos);

        return cmdResponseDtos;
    }

    private void consulHealthCheckAfterDeploy(String serviceName, List<CmdResponseDto> cmdResponseDtos, float version) {
        try {
            CmdResponseDto cmdResponseDtoForConsulCheck;
            for (int i=0;i<retryNum;i++){
                try {
                    TimeUnit.SECONDS.sleep(retrySec);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                cmdResponseDtoForConsulCheck=consulWatchChecksService(consulServiceFileName,serviceName);
                ConsulHealthCheck consulHealthCheck= ConsulHealthCheckService.consulHealthCheck(cmdResponseDtoForConsulCheck.getResult(),serviceName);
                if ((i==retryNum-1)){
                    if (consulHealthCheck.getStatus().contains("passing")){
                        //部署成功，更新版本号
                        sed(podVersionInitFile,serviceName+":"+Float.parseFloat(String.format("%.1f",version-versionStep)),serviceName+":"+version);
                        stringRedisTemplate.opsForHash().put(PodVersionConfig.podVersionHashName,serviceName,String.valueOf(version));
                    }
                    cmdResponseDtoForConsulCheck.setResult(consulHealthCheck.getServiceName()+":"+consulHealthCheck.getStatus());
                    cmdResponseDtos.add(cmdResponseDtoForConsulCheck);
                }

            }
        } catch (InterruptedException | IOException e) {
            e.printStackTrace();
        }

    }

    public List<CmdResponseDto> autoSimplePublishPod(String serviceName) throws IOException, InterruptedException {
        List<CmdResponseDto> cmdResponseDtos=new ArrayList<>(5);
        String podWorkPath=baseWorkPath+ File.separator+serviceName;
        String tarName=podWorkPath+File.separator+serviceName+tarSuffix;
        String dockerImageName=dockrerRegDomain+serviceName;
        String podFileNameTpl=podWorkPath+File.separator+podPreffix+serviceName+podTplSuffix;
        String podFileName=podWorkPath+File.separator+podPreffix+serviceName+podSuffix;

        float version= Float.parseFloat((String) Objects.requireNonNull(stringRedisTemplate.opsForHash().get(PodVersionConfig.podVersionHashName, serviceName)));
        version+=versionStep;
        version=Float.parseFloat(String.format("%.1f",version));

        CmdResponseDto cmdResponseDtoForTar=uncompressTar(podWorkPath,tarName);
        changeSeparator(podWorkPath+File.separator+"start.sh");
        assignPodFileVersion(podFileNameTpl,podFileName,version);
        CmdResponseDto cmdResponseDtoForCdi=createDockerImage(podWorkPath,dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForPdi=pushDockerImage(dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForDkp=deleteK8sPod(podFileName);
        CmdResponseDto cmdResponseDtoForCkp=createK8sPod(podFileName);
        cmdResponseDtos.add(cmdResponseDtoForTar);
        cmdResponseDtos.add(cmdResponseDtoForCdi);
        cmdResponseDtos.add(cmdResponseDtoForPdi);
        cmdResponseDtos.add(cmdResponseDtoForDkp);
        cmdResponseDtos.add(cmdResponseDtoForCkp);
        consulHealthCheckAfterDeploy(serviceName, cmdResponseDtos, version);
        log.debug("简单pod部署结果:{}",cmdResponseDtos);
        return cmdResponseDtos;
    }

    private void assignPodFileVersion(String podFileNameTpl,String podFileName, float version) {
        Map<String, String> argsMap = new HashMap<>(1);
        argsMap.put("version", String.valueOf(version));

        TransportTemplate transportTemplate = new TransportTemplate();
        try(BufferedReader bufferedReader=new BufferedReader(new FileReader(new File(podFileNameTpl)));
            BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter(new File(podFileName)))){
            Optional<String> optional=bufferedReader.lines().reduce((s, s2) -> s+="\n"+s2);
            optional.orElseThrow(()->new BizException(MsgConstants.KD300001));
            transportTemplate.setTemplateContent(optional.get());
            transportTemplate.setTemplateMap(argsMap);
            transportTemplate.setTemplateName("yaml");
            String tResult=cmdTemplateTransformService.transform(transportTemplate);

            bufferedWriter.write(tResult);
            bufferedWriter.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public List<List<CmdResponseDto>> autoSimplePublishPodByExecutorService(List<String> services){
        if (CollectionUtils.isEmpty(services)){
            throw new BizException(MsgConstants.KD300002);
        }
        LocalDateTime start= LocalDateTime.now();
        List<Future<List<CmdResponseDto>>> futures=new LinkedList<>();
        services.forEach(service -> {
            Future<List<CmdResponseDto>> future=executorService.submit(() -> autoSimplePublishPod(service));
            futures.add(future);
        });
        return autoDeployByExecutorService(services, start, futures);
    }

    public List<List<CmdResponseDto>> autoCompletePublishPodByExecutorService(List<String> services){
        if (CollectionUtils.isEmpty(services)){
            throw new BizException(MsgConstants.KD300002);
        }
        LocalDateTime start= LocalDateTime.now();
        List<Future<List<CmdResponseDto>>> futures=new LinkedList<>();
        services.forEach(service -> {
            Future<List<CmdResponseDto>> future=executorService.submit(() -> autoCompletePublishPod(service));
            futures.add(future);
        });
        return autoDeployByExecutorService(services, start, futures);
    }

    private List<List<CmdResponseDto>> autoDeployByExecutorService(List<String> services, LocalDateTime start, List<Future<List<CmdResponseDto>>> futures) {
        List<List<CmdResponseDto>> responseDtoLists = futures.stream().collect(ArrayList::new, (objects, listFuture) -> {
            try {
                objects.add(listFuture.get());
            } catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        }, ArrayList::addAll);
        LocalDateTime end = LocalDateTime.now();
        Duration duration = Duration.between(start, end);
        log.debug(services + "==>>耗时（s）：{}", duration.getSeconds());
        return responseDtoLists;
    }

    public List<CmdResponseDto> autoSimplePublishIg() throws IOException, InterruptedException {
        String bankingIg="banking-ig";
        String bankingIgApp="banking-integration-app";
        List<CmdResponseDto> cmdResponseDtos=new ArrayList<>(5);
        String podWorkPath=baseWorkPath+ File.separator+"banking-integration";
        String tarName=podWorkPath+File.separator+"banking-integration"+tarSuffix;
        String dockerImageName=dockrerRegDomain+bankingIg;
        String podFileNameTpl=podWorkPath+File.separator+podPreffix+bankingIg+podTplSuffix;
        String podFileName=podWorkPath+File.separator+podPreffix+bankingIg+podSuffix;

        float version= Float.parseFloat((String) Objects
                .requireNonNull(stringRedisTemplate.opsForHash().get(PodVersionConfig.podVersionHashName, bankingIg)));
        version+=versionStep;
        version=Float.parseFloat(String.format("%.1f",version));

        CmdResponseDto cmdResponseDtoForTar=uncompressTar(podWorkPath,tarName);
        changeSeparator(podWorkPath+File.separator+"start.sh");
        assignPodFileVersion(podFileNameTpl,podFileName,version);
        CmdResponseDto cmdResponseDtoForCdi=createDockerImage(podWorkPath,dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForPdi=pushDockerImage(dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForDkp=deleteK8sPod(podFileName);
        CmdResponseDto cmdResponseDtoForCkp=createK8sPod(podFileName);
        cmdResponseDtos.add(cmdResponseDtoForTar);
        cmdResponseDtos.add(cmdResponseDtoForCdi);
        cmdResponseDtos.add(cmdResponseDtoForPdi);
        cmdResponseDtos.add(cmdResponseDtoForDkp);
        cmdResponseDtos.add(cmdResponseDtoForCkp);
        consulHealthCheckAfterDeploy(bankingIgApp, cmdResponseDtos, version);
        log.debug("完全pod部署结果:{}",cmdResponseDtos);
        return cmdResponseDtos;
    }

    public List<CmdResponseDto> autoCompletePublishIg() throws IOException, InterruptedException {
        String bankingIg="banking-ig";
        String bankingIgApp="banking-integration-app";
        List<CmdResponseDto> cmdResponseDtos=new ArrayList<>(7);
        String podWorkPath=baseWorkPath+ File.separator+"banking-integration";
        String tarName=podWorkPath+File.separator+"banking-integration"+tarSuffix;
        String dockerImageName=dockrerRegDomain+bankingIg;
        String configFilePath=podWorkPath+File.separator+configDirName;
        String configMapName=bankingIg+configmapSuffix;
        String podFileNameTpl=podWorkPath+File.separator+podPreffix+bankingIg+podTplSuffix;
        String podFileName=podWorkPath+File.separator+podPreffix+bankingIg+podSuffix;

        float version= Float.parseFloat((String) Objects
                .requireNonNull(stringRedisTemplate.opsForHash()
                .get(PodVersionConfig.podVersionHashName, bankingIg)));
        version+=versionStep;
        version=Float.parseFloat(String.format("%.1f",version));

        CmdResponseDto cmdResponseDtoForTar=uncompressTar(podWorkPath,tarName);
        changeSeparator(podWorkPath+File.separator+"start.sh");
        assignPodFileVersion(podFileNameTpl,podFileName,version);
        CmdResponseDto cmdResponseDtoForCdi=createDockerImage(podWorkPath,dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForPdi=pushDockerImage(dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForDcm=deleteConfigMap(configMapName,"");
        CmdResponseDto cmdResponseDtoForCcm=createConfigMap(configFilePath,configMapName,"");
        CmdResponseDto cmdResponseDtoForDkp=deleteK8sPod(podFileName);
        CmdResponseDto cmdResponseDtoForCkp=createK8sPod(podFileName);
        cmdResponseDtos.add(cmdResponseDtoForTar);
        cmdResponseDtos.add(cmdResponseDtoForCdi);
        cmdResponseDtos.add(cmdResponseDtoForPdi);
        cmdResponseDtos.add(cmdResponseDtoForDcm);
        cmdResponseDtos.add(cmdResponseDtoForCcm);
        cmdResponseDtos.add(cmdResponseDtoForDkp);
        cmdResponseDtos.add(cmdResponseDtoForCkp);

        consulHealthCheckAfterDeploy(bankingIgApp, cmdResponseDtos, version);
        log.debug("完全pod部署结果:{}",cmdResponseDtos);

        return cmdResponseDtos;
    }

    public List<CmdResponseDto> autoCompletePublishWeb() throws IOException, InterruptedException {
        List<CmdResponseDto> cmdResponseDtos=new ArrayList<>(8);
        String serviceName="banking-admin-web";
        String podWorkPath=baseWorkPath+ File.separator+serviceName;
        String distDir=podWorkPath+File.separator+"dist";
        String zipName=podWorkPath+File.separator+"dist.zip";
        String dockerImageName=dockrerRegDomain+serviceName;
        String configFile=podWorkPath+File.separator+"nginx.conf";
        String configMapName=serviceName+configmapSuffix;
        String podFileNameTpl=podWorkPath+File.separator+podPreffix+serviceName+podTplSuffix;
        String podFileName=podWorkPath+File.separator+podPreffix+serviceName+podSuffix;

        float version= Float.parseFloat((String) Objects.requireNonNull(stringRedisTemplate.opsForHash().get(PodVersionConfig.podVersionHashName, serviceName)));
        version+=versionStep;
        version=Float.parseFloat(String.format("%.1f",version));

        CmdResponseDto cmdResponseDtoForRm=rm(distDir);
        CmdResponseDto cmdResponseDtoForZip=uncompressZip(podWorkPath,zipName);
        assignPodFileVersion(podFileNameTpl,podFileName,version);
        CmdResponseDto cmdResponseDtoForCdi=createDockerImage(podWorkPath,dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForPdi=pushDockerImage(dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForDcm=deleteConfigMap(configMapName,"");
        CmdResponseDto cmdResponseDtoForCcm=createConfigMap(configFile,configMapName,"");
        CmdResponseDto cmdResponseDtoForDkp=deleteK8sPod(podFileName);
        CmdResponseDto cmdResponseDtoForCkp=createK8sPod(podFileName);
        cmdResponseDtos.add(cmdResponseDtoForRm);
        cmdResponseDtos.add(cmdResponseDtoForZip);
        cmdResponseDtos.add(cmdResponseDtoForCdi);
        cmdResponseDtos.add(cmdResponseDtoForPdi);
        cmdResponseDtos.add(cmdResponseDtoForDcm);
        cmdResponseDtos.add(cmdResponseDtoForCcm);
        cmdResponseDtos.add(cmdResponseDtoForDkp);
        cmdResponseDtos.add(cmdResponseDtoForCkp);

        sed(podVersionInitFile,serviceName+":"+Float.parseFloat(String.format("%.1f",version-versionStep)),serviceName+":"+version);
        stringRedisTemplate.opsForHash().put(PodVersionConfig.podVersionHashName,serviceName,String.valueOf(version));

        log.debug("完全pod部署结果:{}",cmdResponseDtos);

        return cmdResponseDtos;
    }

    public List<CmdResponseDto> autoSimplePublishWeb() throws IOException, InterruptedException {
        List<CmdResponseDto> cmdResponseDtos=new ArrayList<>(6);
        String serviceName="banking-admin-web";
        String podWorkPath=baseWorkPath+ File.separator+serviceName;
        String distDir=podWorkPath+File.separator+"dist";
        String zipName=podWorkPath+File.separator+"dist.zip";
        String dockerImageName=dockrerRegDomain+serviceName;
        String podFileNameTpl=podWorkPath+File.separator+podPreffix+serviceName+podTplSuffix;
        String podFileName=podWorkPath+File.separator+podPreffix+serviceName+podSuffix;

        float version= Float.parseFloat((String) Objects.requireNonNull(stringRedisTemplate.opsForHash().get(PodVersionConfig.podVersionHashName, serviceName)));
        version+=versionStep;
        version=Float.parseFloat(String.format("%.1f",version));

        CmdResponseDto cmdResponseDtoForRm=rm(distDir);
        CmdResponseDto cmdResponseDtoForZip=uncompressZip(podWorkPath,zipName);
        assignPodFileVersion(podFileNameTpl,podFileName,version);
        CmdResponseDto cmdResponseDtoForCdi=createDockerImage(podWorkPath,dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForPdi=pushDockerImage(dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForDkp=deleteK8sPod(podFileName);
        CmdResponseDto cmdResponseDtoForCkp=createK8sPod(podFileName);
        cmdResponseDtos.add(cmdResponseDtoForRm);
        cmdResponseDtos.add(cmdResponseDtoForZip);
        cmdResponseDtos.add(cmdResponseDtoForCdi);
        cmdResponseDtos.add(cmdResponseDtoForPdi);
        cmdResponseDtos.add(cmdResponseDtoForDkp);
        cmdResponseDtos.add(cmdResponseDtoForCkp);

        sed(podVersionInitFile,serviceName+":"+Float.parseFloat(String.format("%.1f",version-versionStep)),serviceName+":"+version);
        stringRedisTemplate.opsForHash().put(PodVersionConfig.podVersionHashName,serviceName,String.valueOf(version));

        log.debug("简单pod部署结果:{}",cmdResponseDtos);
        return cmdResponseDtos;
    }

    public List<CmdResponseDto> autoCompletePublishAdmin() throws IOException, InterruptedException {
        List<CmdResponseDto> cmdResponseDtos=new ArrayList<>(7);
        String serviceName="banking-core-admin";
        String appName="banking-admin-core";
        String podWorkPath=baseWorkPath+ File.separator+serviceName;
        String tarName=podWorkPath+File.separator+serviceName+"-1.0-SNAPSHOT.tar.gz";
        String dockerImageName=dockrerRegDomain+appName;
        String configFilePath=podWorkPath+File.separator+configDirName;
        String configMapName=appName+configmapSuffix;
        String podFileNameTpl=podWorkPath+File.separator+podPreffix+appName+podTplSuffix;
        String podFileName=podWorkPath+File.separator+podPreffix+appName+podSuffix;

        float version= Float.parseFloat((String) Objects.requireNonNull(stringRedisTemplate.opsForHash().get(PodVersionConfig.podVersionHashName, appName)));
        version+=versionStep;
        version=Float.parseFloat(String.format("%.1f",version));

        CmdResponseDto cmdResponseDtoForTar=uncompressTar(podWorkPath,tarName);
        changeSeparator(podWorkPath+File.separator+"start.sh");
        assignPodFileVersion(podFileNameTpl,podFileName,version);
        CmdResponseDto cmdResponseDtoForCdi=createDockerImage(podWorkPath,dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForPdi=pushDockerImage(dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForDcm=deleteConfigMap(configMapName,"");
        CmdResponseDto cmdResponseDtoForCcm=createConfigMap(configFilePath,configMapName,"");
        CmdResponseDto cmdResponseDtoForDkp=deleteK8sPod(podFileName);
        CmdResponseDto cmdResponseDtoForCkp=createK8sPod(podFileName);
        cmdResponseDtos.add(cmdResponseDtoForTar);
        cmdResponseDtos.add(cmdResponseDtoForCdi);
        cmdResponseDtos.add(cmdResponseDtoForPdi);
        cmdResponseDtos.add(cmdResponseDtoForDcm);
        cmdResponseDtos.add(cmdResponseDtoForCcm);
        cmdResponseDtos.add(cmdResponseDtoForDkp);
        cmdResponseDtos.add(cmdResponseDtoForCkp);

        consulHealthCheckAfterDeploy(serviceName, cmdResponseDtos, version);
        log.debug("完全pod部署结果:{}",cmdResponseDtos);

        return cmdResponseDtos;
    }

    public List<CmdResponseDto> autoSimplePublishAdmin() throws IOException, InterruptedException {
        List<CmdResponseDto> cmdResponseDtos=new ArrayList<>(5);
        String serviceName="banking-core-admin";
        String appName="banking-admin-core";
        String podWorkPath=baseWorkPath+ File.separator+serviceName;
        String tarName=podWorkPath+File.separator+serviceName+"-1.0-SNAPSHOT.tar.gz";
        String dockerImageName=dockrerRegDomain+appName;
        String podFileNameTpl=podWorkPath+File.separator+podPreffix+appName+podTplSuffix;
        String podFileName=podWorkPath+File.separator+podPreffix+appName+podSuffix;

        float version= Float.parseFloat((String) Objects.requireNonNull(stringRedisTemplate.opsForHash().get(PodVersionConfig.podVersionHashName, appName)));
        version+=versionStep;
        version=Float.parseFloat(String.format("%.1f",version));

        CmdResponseDto cmdResponseDtoForTar=uncompressTar(podWorkPath,tarName);
        changeSeparator(podWorkPath+File.separator+"start.sh");
        assignPodFileVersion(podFileNameTpl,podFileName,version);
        CmdResponseDto cmdResponseDtoForCdi=createDockerImage(podWorkPath,dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForPdi=pushDockerImage(dockerImageName+":"+version);
        CmdResponseDto cmdResponseDtoForDkp=deleteK8sPod(podFileName);
        CmdResponseDto cmdResponseDtoForCkp=createK8sPod(podFileName);
        cmdResponseDtos.add(cmdResponseDtoForTar);
        cmdResponseDtos.add(cmdResponseDtoForCdi);
        cmdResponseDtos.add(cmdResponseDtoForPdi);
        cmdResponseDtos.add(cmdResponseDtoForDkp);
        cmdResponseDtos.add(cmdResponseDtoForCkp);
        consulHealthCheckAfterDeploy(serviceName, cmdResponseDtos, version);
        log.debug("简单pod部署结果:{}",cmdResponseDtos);
        return cmdResponseDtos;
    }
}
